<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  medias
 */

class m_medias_actions_block_MceObjectFolderContentAction extends m_backoffice_extends_Action
{
	public function execute()
	{
        
        $rootFolder = $this->getRequestParameter("rootFolder");
		$folderLang = $this->getRequestParameter("folderLang");
		$folderId = $this->getRequestParameter("folderId");
		
		if(is_null($folderId))
		{
			$folder = m_backoffice_services_RootNodeService::getInstance()->getModuleRootNode($rootFolder);
		}
		else
		{
			$folder = $this->getDocumentProvider()->getByUniqueId($folderId, $folderLang);
		}
						
		if($folder instanceof m_backoffice_documents_Folder)
		{
            $this->addToModel("rootFolder", $rootFolder);
            if($rootFolder == "medias")
            {
                $this->addToModel("objects", $folder->getMedia());
                $this->addToModel("nbObjects", $folder->getMediaNb());
            }
            else
            {
                $this->addToModel("objects", $folder->getItem());
                $this->addToModel("nbObjects", $folder->getItemNb());
            }
		}
		else
		{
			$this->addToModel("objects", "home");
		}
		
		$this->setView('success');
	}	
	
	public function getBreadCrump($id, $docType, $lang)
	{
		$parents = f_relation_Manager::getInstance()->getParentsByDocType($id, $docType, $lang);
		$breadCrumb = Array();
		foreach($parents as $parent)
		{
			$breadCrumb[] = $parent->getLabel();
		}
		
		$breadCrumb = join(" &gt; ", $breadCrumb);
		return $breadCrumb;
	}
}